﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient


Public Class PaisesDB
    Public Shared Function GetPaises() As DataSet
        Dim cmd As New SqlCommand("spGetPaises", DB.Conexion)
        Dim da As New SqlDataAdapter
        Dim ds As New DataSet

        cmd.CommandType = CommandType.StoredProcedure
        da.SelectCommand = cmd
        da.Fill(ds, "Paises")
        Return ds
    End Function
    Public Shared Sub InsertarPais(ByVal pais As String)
        Dim cmd As New SqlCommand("spInsertPais", DB.Conexion)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@pais", pais)
        cmd.Parameters.Add("@Error", SqlDbType.Int).Direction = ParameterDirection.Output
        cmd.Parameters.Add("@ErrorDesc", SqlDbType.VarChar, 200).Direction = ParameterDirection.Output
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
        If cmd.Parameters("@error").Value <> 0 Then
            Throw New ApplicationException(cmd.Parameters("@ErrorDesc").Value.ToString())
        End If
        
        
    End Sub

    Public Shared Sub EliminarPais(ByVal id_pais As Integer)
        Dim cmd As New SqlCommand("spDeletePais", DB.Conexion)

        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@id_pais", id_pais)
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
    End Sub

    Public Shared Sub ActualizarPais(ByVal id_pais As Integer, ByVal pais As String)
        Dim cmd As New SqlCommand("spUpdatePais", DB.Conexion)

        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@id_pais", id_pais)
        cmd.Parameters.AddWithValue("@pais", pais)
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
    End Sub
End Class
